# -*- coding: utf-8 -*-
"""
author:码同学 极光
date:2023-01-14
desc: 
sample: 
"""
import requests

host = 'http://82.156.74.26:9088'

def testcookie():
   url = host+"/pinter/bank/api/login"
   data={
       'userName':'admin',
       'password': '1234',
   }
   session = requests.session() #一次连接 会话
   response = session.post(url, data = data)
   print(f"是否成功{response.status_code}")
   print(f"返回结果{response.text}")

   data = {
     'userName':'admin'
   }
   url = host + "/pinter/bank/api/query"
   response = session.get(url, params=data)
   print(f"是否成功{response.status_code}")
   print(f"返回结果{response.text}")

def testtoken():
    url = host + "/pinter/bank/api/login2"
    data = {
        'userName': 'admin',
        'password': '1234',
    }
    response = requests.post(url, data=data)
    print(f"是否成功{response.status_code}")
    print(f"返回结果{response.text}")
    #提取处理
    json  = response.json()
    token = json["data"]
    print(token)

    data = {
        'userName': 'admin'
    }
    url = host + "/pinter/bank/api/query2"
    headers = {
        #开发提供
        'testfan-token': token
    }
    response = requests.get(url, params=data,headers=headers)
    print(f"是否成功{response.status_code}")
    print(f"返回结果{response.text}")


if __name__ == '__main__':
    testcookie()
    testtoken()

